package test;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import com.ssish.common.insurance.utils.RSAUtil;

public class HttpTest {
	private static final String DEFAULT_CHARSET="UTF-8";
	//本地秘钥
	private static final String privateKey="MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAIYL0bRy5POTzgvWam10TZzuIrFocBEKUXwecDUgbRU8Zy3QszkqpaOljJ6Yr6/4QpsyM8WsgL6QN4pPKgZK+IDOIDR0HpcwcTmtQiVwDU4Lws1tEKyGfEunQU9wpmPKdJ/GhiG45QJESYTpBZUI+XiXswo1GCRxl0RzWmlZTWSzAgMBAAECgYAZ8GuSKbGYWP/EVqedqqXiOkrIXddh1MdT52f7P90cAOZOfVZRN6l58200u4Mz4Cyzb5GJLQp01d+Jiiwtr5BKwTsqJN7M4D+4XhTti1fQ82iznR6FWnDUPAGpB6qXrZ0rGb2sNHkrPTJCWfth12I1VOEkiSlKpqlbIaWNmObqIQJBAP7B9GpvLc98pailqdu/5P8l+goUYq/y+M7mlVznIAnj+alNaxM37TO1hULtqXlTJx4Ct4pH4RVxK0AYCuMZoYkCQQCGsypbdc4/ZOGTtFmpRLlyJ9jM1rFAjNKGhal1F5JknthwnWccbF8Zl1vQSamJgxlqs3vXOfYWqwxXdZOAZ/FbAkAAxAp9C2qC1igVUrIpA/GnRrDyuM73Im7XCGBokBVLklDczmvE+gUPg7sr0VUSFUrnzzBIDSFDFD0CC1B1EE2pAkADSVXMO3iXxV9XmjvhzGJ17ZD1lntmpsjwLUywJa4VtGZ1gPGmGOLNHgtIbrOrPj6dgtmPq8NcVDoN3DmIFYEnAkA+qxrK09WhuBQMD0BEznWJVS6QppRwTCnJC2soRICQ9kDyxr2+71diHZNMBjLpmx5e0ktvdLYcJ26zs9QSQLMh";
	private static final String url="http://106.14.160.98/ins-plus/api/diccshjdjf";//001 渠道代码
	public Object invokeForObject(String xml,Map<String,Object> extendMap) throws Exception {
		System.out.println("请求报文=="+xml);
		xml=RSAUtil.encryptByPrivateKey(xml, privateKey);
		@SuppressWarnings("deprecation")
		HttpClient httpclient = new DefaultHttpClient();
		HttpPost post=new HttpPost(url);//测试环境
		post.setEntity(new StringEntity(xml, "UTF-8"));
		HttpResponse response = httpclient.execute(post);
		String respStr = EntityUtils.toString(response.getEntity(),"UTF-8");
		respStr=RSAUtil.decryptByPrivateKey(respStr, privateKey);
		System.out.println("返回报文="+respStr);
		return respStr;
	}
}
